{% extends 'purchaseSys/purSysIndex.html' %}
{% block title %}
仓库查询
{% endblock %}

{% block style %}
    <style>
        .create{
            width: 100%;
        }

        .form-control{
            width: 100%;
        }
        .create th{
            width: 7%;
        }
        .create td{
            width: 20%;
        }
        #cangku_table{
            width: 90%;
        }
        .red{
            color:red;
        }
        #body td{
            text-align: center;
            vertical-align: top;
        }
        th {
            text-align: center;
            line-height: 29px;
        }
        #msg{
            width: 100px;
            height: 250px;
            position: fixed;
            right: 7px;
            top: 191px;
            background-color: gainsboro;
         }
        #msg h1{
            line-height: 1.7;
            max-width: 15px;
            margin: 0 28px;
            {#font-size: 2em;#}
            color: #46aa58;
        }
    </style>
{% endblock %}

{% block body %}
    <div class="create">
        <form action="" method="post" id="form_query">
            <input type="hidden" name="operate" value="add">
            <table class='table table-hover danger 'border="2px" cellpadding="0" cellspacing="0" >
                <tr>
                    <th>{{ cangku_form.gno.label_tag }}</th>
                    <td>{{ cangku_form.gno }}<span class="red">{{ cangku_form.errors.gno.0 }}</span></td>
                    <th>{{ cangku_form.gtype.label_tag }}</th>
                    <td>{{ cangku_form.gtype }}<span class="red">{{ cangku_form.errors.gtype.0 }}</span></td>
                    <th>{{ cangku_form.gname.label_tag }}</th>
                    <td>{{ cangku_form.gname }}<span class="red">{{ cangku_form.errors.gname.0 }}</span></td>
                    <th>{{ cangku_form.gmer.label_tag }}</th>
                    <td>{{ cangku_form.gmer }}<span class="red">{{ cangku_form.errors.gmer.0 }}</span></td>
                    <td rowspan="3">
                        <input type="submit" class="gaofei_btn btn-success" value="保存">
                         <input type="reset" class="gaofei_btn btn-info" value="重置" onclick="reset_query(this);">
                    </td>
                </tr>
                <tr>
                    <th>{{ cangku_form.gsize.label_tag }}</th>
                    <td>{{ cangku_form.gsize }}<span class="red">{{ cangku_form.errors.gsize.0 }}</span></td>
                    <th>{{ cangku_form.gcolor.label_tag }}</th>
                    <td>{{ cangku_form.gcolor }}<span class="red">{{ cangku_form.errors.gcolor.0 }}</span></td>
                    <th>{{ cangku_form.gnums.label_tag }}</th>
                    <td>{{ cangku_form.gnums }}<span class="red">{{ cangku_form.errors.gnums.0 }}</span></td>
                    <th>{{ cangku_form.gcount.label_tag }}</th>
                    <td>{{ cangku_form.gcount }}<span class="red">{{ cangku_form.errors.gcount.0 }}</span></td>
                </tr>
                <tr>
                    <th>{{ cangku_form.ghandle.label_tag }}</th>
                    <td>{{ cangku_form.ghandle }}<span class="red">{{ cangku_form.errors.ghandle.0 }}</span></td>
                    <th>{{ cangku_form.gprice1.label_tag }}</th>
                    <td>{{ cangku_form.gprice1 }}<span class="red">{{ cangku_form.errors.gprice1.0 }}</span></td>
                    <th>{{ cangku_form.gprice2.label_tag }}</th>
                    <td>{{ cangku_form.gprice2 }}<span class="red">{{ cangku_form.errors.gprice2.0 }}</span></td>
                    <th>{{ cangku_form.gtime.label_tag }}</th>
                    <td>{{ cangku_form.gtime }}<span class="red">{{ cangku_form.errors.gtime.0 }}</span></td>
    {#                <th>{{ cangku_form.gprofit.label_tag }}</th>#}
    {#                <td>{{ cangku_form.gprofit }}</td>#}
                </tr>
            </table>
        </form>
    </div>
    <div class="show">
        <table id="cangku_table" class='table table-hover danger 'border="0" cellpadding="0" cellspacing="0" width="80%">
            <th>序号</th>
            <th>{{ cangku_form.gno.label }}</th>
            <th>{{ cangku_form.gtype.label }}</th>
            <th>{{ cangku_form.gname.label }}</th>
            <th>{{ cangku_form.gmer.label }}</th>
            <th>{{ cangku_form.gsize.label }}</th>
            <th>{{ cangku_form.gcolor.label }}</th>
            <th>{{ cangku_form.gnums.label }}</th>
            <th>{{ cangku_form.gcount.label }}</th>
            <th>{{ cangku_form.ghandle.label }}</th>
            <th>{{ cangku_form.gprice1.label }}</th>
            <th>{{ cangku_form.gprice2.label }}</th>
            <th>利润</th>
            <th>{{ cangku_form.gtime.label }}</th>
            <th>操作</th>

            {% for cangku in all_cangku %}
                <tr class="bg-success">
                    <input type="hidden" name="id" value="{{ cangku.id }}">
                    <td>{{ forloop.counter }}</td>
                    <td class="cangku_upd_">{{ cangku.gno }}</td>
                    <td class="cangku_upd_01" sele="{{ cangku.gtype.id }}">{{ cangku.gtype.gname }}</td>
                    <td class="cangku_upd_">{{ cangku.gname }}</td>
                    <td class="cangku_upd_01" sele="{{ cangku.gmer.id }}">{{ cangku.gmer.mname }}</td>
                    <td class="cangku_upd_01" sele="{{ cangku.gsize.id }}">{{ cangku.gsize.sname }}</td>
                    <td class="cangku_upd_01" sele="{{ cangku.gcolor.id }}">{{ cangku.gcolor.cname }}</td>
                    <td class="cangku_upd_">{{ cangku.gnums }}</td>
                    <td class="cangku_upd_">{{ cangku.gcount }}</td>
                    <td class="cangku_upd_">{{ cangku.ghandle }}</td>
                    <td class="cangku_upd_">{{ cangku.gprice1 }}</td>
                    <td class="cangku_upd_">{{ cangku.gprice2 }}</td>
                    <td>{{ cangku.gprofit }}</td>
                    <td class="cangku_upd_">{{ cangku.gtime|date:"Y-m-d H:i:s" }}</td>
                    <td>
                        <a href="" class="btn btn btn-success " data-toggle="modal" data-target="#myModal" onclick="udp(this);">修改</a>
                        <a href="" class="btn btn-danger" data-toggle="modal" data-target="#myModal_del" onclick="del(this);">删除</a>
                    </td>
                </tr>
            {% endfor %}

        </table>
    </div>

    {#修改对话框#}
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">修改</h4>
                </div>
                <div class="modal-body">
                    <form action="" id="form_upd" method="post">
                        <input type="hidden" name="id">
                        <input type="hidden" name="operate" value="upd">
                        {{ cangku_form.gno.label_tag }}
                        {{ cangku_form.gno }}
                        {{ cangku_form.gtype.label_tag }}
                        {{ cangku_form.gtype }}
                        {{ cangku_form.gname.label_tag }}
                        {{ cangku_form.gname }}
                        {{ cangku_form.gmer.label_tag }}
                        {{ cangku_form.gmer }}

                        {{ cangku_form.gsize.label_tag }}
                        {{ cangku_form.gsize }}
                        {{ cangku_form.gcolor.label_tag }}
                        {{ cangku_form.gcolor }}
                        {{ cangku_form.gnums.label_tag }}
                        {{ cangku_form.gnums }}
                        {{ cangku_form.gcount.label_tag }}
                        {{ cangku_form.gcount }}

                        {{ cangku_form.ghandle.label_tag }}
                        {{ cangku_form.ghandle }}
                        {{ cangku_form.gprice1.label_tag }}
                        {{ cangku_form.gprice1 }}
                        {{ cangku_form.gprice2.label_tag }}
                        {{ cangku_form.gprice2 }}
                        {{ cangku_form.gtime.label_tag }}
                        {{ cangku_form.gtime }}

                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="save_upd(this);">提交更改</button>
                </div>
            </div>
        </div>
    </div>

    {# 删除#}
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal_del" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        模态框（Modal）标题
                    </h4>
                </div>
                <div class="modal-body" id="model-body_del">
                    <form action="" method="post" id="form_del">
                        <input type="hidden" name="id">
                        <input type="hidden" name="operate" value="del0" >
                    </form>
                    确认删除？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" onclick="save_del(this);">
                        提交更改
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->




</div>

{% endblock %}

{#{% block msg %}#}
{#    {{ msg_add }}{{ msg_upd }}{{ msg_del }}#}
{#{% endblock %}#}

{% block script %}
    <script>

         function reset_query(self) {
            //重置表单
            $('#form_query input:text,#form_query input[type="number"]').attr('value','')
            $('#form_query select:eq(0)').attr('value','0')
            $('#form_query select:eq(1)').attr('value','0')
            $('#form_query select:eq(2)').attr('value','0')
            $('#form_query select:eq(3)').attr('value','0')
            console.log($('#form_query input:eq(0)'));
        }

            $('.modal-body input').val('')  //初始化空值，避免错乱

            function udp(self) {
                $('.modal-body input').val('')  //初始化空值，避免错乱

                $('.modal-body input[type="hidden"]').val($(self).parent().parent().find('input:hidden').val())
                console.log($('.modal-body input[type="hidden"]'));

                $.each($(self).parent().parent().find('.cangku_upd_'),function (x,y) {
                    {#console.log(x);#}
                    {#console.log(y);#}
                    {#console.log(11111,$('.modal-body input').eq(x));#}
                    {#console.log(22222,  $(y).html());#}
                    $('.modal-body .cangku_upd').eq(x).val($(y).html().trim())
                    {#console.log($('.modal-body .cangku_upd').eq(x), $(y).html().trim());#}
                    {#$('.modal-body input').eq(x).val(1)#}
                })

                $.each($(self).parent().parent().find('.cangku_upd_01'),function(x,y){
                    $('.modal-body .cangku_upd_01').eq(x).val($(y).attr('sele'))
                    console.log($('.modal-body .cangku_upd_01').eq(x), $(y).attr('sele'));
                })
            }
            

            {#function save_upd(self) {#}
            {#    $('#form_upd').submit()#}
            {#}#}
            
            function del(self) {
                $('#model-body_del input').first().val($(self).parent().parent().find('input:hidden').val())
                $('#model-body_del input').last().val('del')

            }
            
            function save_del(self) {
                $('#form_del').submit()
            }
    </script>
{% endblock %}